﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace MPic.Utility
{
    public class IPHelper
    {
        public static string getIPAddr()
        {
            string user_IP = string.Empty;
            try
            {
                if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                {
                    user_IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    user_IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
                }
            }
            catch
            {
                try
                {
                    user_IP = HttpContext.Current.Request.UserHostAddress;
                }
                catch (Exception)
                {
                    user_IP = "192.168.1.1";
                }

            }
            return user_IP;
        }
    }
}
